﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SLG.Domain
{
    public class SLGDbContext : DbContext
    {
        public SLGDbContext()
            : base("name=slg_db")
        {
            Database.SetInitializer<SLGDbContext>(null);
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<Entities.SYS_User>().ToTable("slg_sys_user");
            modelBuilder.Entity<Entities.SYS_User>().HasKey(p => p.Id);

            modelBuilder.Entity<Entities.BD_Race>().ToTable("slg_bd_race");
            modelBuilder.Entity<Entities.BD_Race>().HasKey(p => p.Id);

            modelBuilder.Entity<Entities.BD_Avatar>().ToTable("slg_bd_avatar");
            modelBuilder.Entity<Entities.BD_Avatar>().HasKey(p => p.Id);

            #region views
            modelBuilder.Entity<Views.V_BD_King>().ToTable("slg_v_bd_king");
            modelBuilder.Entity<Views.V_BD_King>().HasKey(p => p.Id);
            #endregion

            modelBuilder.Entity<Entities.T_Avatar>().ToTable("slg_t_avatar");
            modelBuilder.Entity<Entities.T_Avatar>().HasKey(p => p.Id);

            modelBuilder.Entity<Entities.T_Kingdom>().ToTable("slg_t_kingdom");
            modelBuilder.Entity<Entities.T_Kingdom>().HasKey(p => p.Id);

            modelBuilder.Entity<Entities.T_City>().ToTable("slg_t_city");
            modelBuilder.Entity<Entities.T_City>().HasKey(p => p.Id);

            modelBuilder.Entity<Entities.T_King>().ToTable("slg_t_king");
            modelBuilder.Entity<Entities.T_King>().HasKey(p => p.Id);

            modelBuilder.Entity<Entities.T_Hero>().ToTable("slg_t_hero");
            modelBuilder.Entity<Entities.T_Hero>().HasKey(p => p.Id);

            modelBuilder.Entity<Entities.T_Building>().ToTable("slg_t_building");
            modelBuilder.Entity<Entities.T_Building>().HasKey(p => p.Id);

            modelBuilder.Entity<Entities.T_Resource>().ToTable("slg_t_resource");
            modelBuilder.Entity<Entities.T_Resource>().HasKey(p => new { p.Id, p.CityId });

            modelBuilder.Entity<Entities.T_Army>().ToTable("slg_t_army");
            modelBuilder.Entity<Entities.T_Army>().HasKey(p => p.Id);

            modelBuilder.Entity<Entities.T_Army_Unit>().ToTable("slg_t_army_unit");
            modelBuilder.Entity<Entities.T_Army_Unit>().HasKey(p => p.Id);
        }
    }
}
